package com.ruoyi.industry.controller.pc;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.web.page.TableDataList;
import com.ruoyi.industry.domain.SpaceIndustry;
import com.ruoyi.industry.domain.SpaceIndustryVo;
import com.ruoyi.industry.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 登陆后首页Controller
 *
 * @author MagicCube
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/frontend/spaceIndustry")
public class PCSpaceIndustryController extends BaseController {
    @Autowired
    private ISpaceIndustryService spaceIndustryService;
    /*楼宇*/
    @Autowired
    private IProjectBuildingService projectBuildingService;
    /*仓库*/
    @Autowired
    private IProjectWarehouseService projectWarehouseService;
    /*厂房*/
    @Autowired
    private IProjectWorkshopService projectWorkshopService;
    /*公寓*/
    @Autowired
    private IProjectApartmentService projectApartmentService;
    /*拍卖*/
    @Autowired
    private IProjectAuctionService projectAuctionService;
    /*土地*/
    @Autowired
    private IProjectLandService projectLandService;
    /*园区*/
    @Autowired
    private IProjectParkService projectParkService;

    /**
     * 综合列表
     * @param spaceIndustry 产业信息
     * @return 综合产业列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryListz(spaceIndustry,true);
        return getDataTable(spaceIndustries);
    }

    /**
     * 热门推荐
     * @param spaceIndustry 产业信息查询条件
     * @return 结果
     */
    @GetMapping("/hotList")
    public TableDataInfo hotList(SpaceIndustry spaceIndustry){
        startPage();
        spaceIndustry.setRecomState(1L);
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryListz(spaceIndustry,true);
        return getDataTable(spaceIndustries);
    }

    /**
     * 优质资源
     * @param spaceIndustry 产业信息查询条件
     * @return 结果
     */
    @GetMapping("/highGrade")
    public TableDataInfo highGrade(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectHighGradeList(spaceIndustry);
        return  getDataTable(spaceIndustries);
    }
    @GetMapping("/compare")
    public TableDataList compare(SpaceIndustryVo spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryList(spaceIndustry);
        return getDataList(spaceIndustries);
    }

    @GetMapping("/spaceList")
    public TableDataList spaceList(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryListz(spaceIndustry,true);
        return getDataList(spaceIndustries);
    }

    /**
     * 人气最高
     * @param spaceIndustry 产业信息
     * @return 结果
     */
    @GetMapping("/popularList")
    public TableDataInfo popularList(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryPopularList(spaceIndustry,true);
        return getDataTable(spaceIndustries);
    }
    /**
     * 最新上架
     * @param spaceIndustry 产业信息
     * @return 结果
     */
    @GetMapping("/newlyAddedList")
    public TableDataInfo newlyAddedList(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceIndustryNewlyAddedList(spaceIndustry,true);
        return getDataTable(spaceIndustries);
    }

    /**
     * 查询发布列表
     * @param spaceIndustry 发布参数信息
     * @return 结果
     */
    @GetMapping("/checkIssueList")
    public TableDataInfo checkIssueList(SpaceIndustry spaceIndustry){
        startPage();
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectSpaceCheckIssueList(spaceIndustry);
        return getDataTable(spaceIndustries);
    }

    /**
     * 查看详情
     */
    @GetMapping("/spaceInfo")
    public AjaxResult spaceInfo(SpaceIndustry spaceIndustry){
//        spaceIndustryService.updatePageViews(spaceIndustry.getSpaceId());
        switch (spaceIndustry.getBuildType()){
            case 1:
                return AjaxResult.success(projectParkService.selectProjectParkByNumber(spaceIndustry.getSpaceId(),true));
            case 2:
            case 3:
                return AjaxResult.success(projectBuildingService.selectProjectBuildingByNumber(spaceIndustry.getSpaceId(),true));
            case 4:
                return AjaxResult.success(projectWarehouseService.selectProjectWarehouseByNumber(spaceIndustry.getSpaceId(),true));
            case 5:
                return AjaxResult.success(projectWorkshopService.selectProjectWorkshopByNumber(spaceIndustry.getSpaceId(),true));
            case 6:
                return AjaxResult.success(projectApartmentService.selectProjectApartmentByNumber(spaceIndustry.getSpaceId(),true));
            case 7:
                return AjaxResult.success(projectAuctionService.selectProjectAuctionByNumber(spaceIndustry.getSpaceId(),true));
            case 8:
                return AjaxResult.success(projectLandService.selectProjectLandByNumber(spaceIndustry.getSpaceId(),true));
            default:
                return AjaxResult.success();
        }
    }

    /**
     * 查看详情(不增加浏览量)
     */
    @GetMapping("/spaceInfoz")
    public AjaxResult spaceInfoz(SpaceIndustry spaceIndustry){
        switch (spaceIndustry.getBuildType()){
            case 1:
                return AjaxResult.success(projectParkService.selectProjectParkByNumber(spaceIndustry.getSpaceId(),false));
            case 2:
            case 3:
                return AjaxResult.success(projectBuildingService.selectProjectBuildingByNumber(spaceIndustry.getSpaceId(), false));
            case 4:
                return AjaxResult.success(projectWarehouseService.selectProjectWarehouseByNumber(spaceIndustry.getSpaceId(), false));
            case 5:
                return AjaxResult.success(projectWorkshopService.selectProjectWorkshopByNumber(spaceIndustry.getSpaceId(), false));
            case 6:
                return AjaxResult.success(projectApartmentService.selectProjectApartmentByNumber(spaceIndustry.getSpaceId(), false));
            case 7:
                return AjaxResult.success(projectAuctionService.selectProjectAuctionByNumber(spaceIndustry.getSpaceId(), false));
            case 8:
                return AjaxResult.success(projectLandService.selectProjectLandByNumber(spaceIndustry.getSpaceId(), false));
            default:
                return AjaxResult.success();
        }
    }
    /**
     * 查看附近空间
     */
    @GetMapping("/nearbySpace")
    public AjaxResult nearbySpace(SpaceIndustry spaceIndustry){
        List<SpaceIndustry> spaceIndustries = spaceIndustryService.selectNearbySpace(spaceIndustry);
        return AjaxResult.success(spaceIndustries);
    }

    @DeleteMapping("/deleteSpace")
    public AjaxResult deleteSpace(SpaceIndustry spaceIndustry){
        switch (spaceIndustry.getBuildType()){
            case 1:
                return AjaxResult.success(projectParkService.deleteProjectParkBySerialNumber(spaceIndustry.getSpaceId()));
            case 2:
            case 3:
                return AjaxResult.success(projectBuildingService.deleteProjectBuildingBySerialNumber(spaceIndustry.getSpaceId()));
            case 4:
                return AjaxResult.success(projectWarehouseService.deleteProjectWarehouseBySerialNumber(spaceIndustry.getSpaceId()));
            case 5:
                return AjaxResult.success(projectWorkshopService.deleteProjectWorkshopBySerialNumber(spaceIndustry.getSpaceId()));
            case 6:
                return AjaxResult.success(projectApartmentService.deleteProjectApartmentBySerialNumber(spaceIndustry.getSpaceId()));
            case 7:
                return AjaxResult.success(projectAuctionService.deleteProjectAuctionBySerialNumber(spaceIndustry.getSpaceId()));
            case 8:
                return AjaxResult.success(projectLandService.deleteProjectLandBySerialNumber(spaceIndustry.getSpaceId()));
            default:
                return AjaxResult.success();
        }
    }
}
